//
//  main.m
//  Hero
//
//  Created by student6 on 2020/10/7.
//  Copyright © 2020 student6. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "ViewController.h"
#import "hero.h"

int main(int argc, char * argv[]) {
    NSString * appDelegateClassName;
    @autoreleasepool {
        // Setup code that might create autoreleased objects goes here.
        appDelegateClassName = NSStringFromClass([AppDelegate class]);
        NSArray * array = [NSArray arrayWithObjects: @"Zhangfei",@"Guangyu",@"Liubei",@"Kongming", @"Caocao", @"Simayi", @"Xiahoudun", @"Sunquan", @"Luxun", @"Zhouyu", nil];
        NSInteger valueA = arc4random() % 10;
        NSInteger valueB = arc4random() % 10;
        while (valueA == valueB) {
            valueB = arc4random() % 10;
        }
        
        NSString *heroA = [array objectAtIndex:valueA];
        NSString *heroB = [array objectAtIndex:valueB];
        Class HeroA = NSClassFromString(heroA);
        Class HeroB = NSClassFromString(heroB);
        id A = [[HeroA alloc] init];
        id B = [[HeroB alloc] init];
        NSInteger A_BloodValue = [A getBlood_value];
        NSInteger B_BloodValue = [B getBlood_value];
        for (int i = 0; i < 5; i++) {
            if ((A_BloodValue > 0) && (B_BloodValue > 0)) {
                NSLog(@"Round %i", i * 2 + 1);
                [A PKOneUnit];
                [B PKOneUnit];
                B_BloodValue = [A ChooseSkill: [B getBlood_value]];
                [B setBlood_value:B_BloodValue];
                if (B_BloodValue <= 0) {
                    NSLog(@"A win!");
                    break;
                }
                NSLog(@"Round %i", i * 2 + 2);
                [A PKOneUnit];
                [B PKOneUnit];
                A_BloodValue = [B ChooseSkill: [A getBlood_value]];
                [A setBlood_value:A_BloodValue];
                if (A_BloodValue <= 0) {
                    NSLog(@"B win!");
                    break;
                }
            } else {
                if (A_BloodValue <= 0) {
                    NSLog(@"B win!");
                    break;
                } else {
                    NSLog(@"A win!");
                    break;
                }
            }
        }
        if ((A_BloodValue > 0) && (B_BloodValue > 0)) {
            if (A_BloodValue > B_BloodValue) {
                NSLog(@"A win!");
            } else if (A_BloodValue < B_BloodValue){
                NSLog(@"B win!");
            } else {
                NSLog(@"Draw!");
            }
        }
    }
    return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
